CS 5010: Problem Set 9

Out: Monday, November 9, 2015

Due: Monday, November 16, 2014 at 600pm local time.


The goal of this problem set is to help you design simple class systems and methods on them.

As always, you must follow the design recipe, in this case the OO Design Recipe and deliverables as spelled out in Lesson 9.5 and in deliverables.html Be sure to sync your work and fill out a Work Session Report at the end of every work session. Use the Work Session Report for PS09.

Please restrict yourself to the language features discussed in class. In particular, you may NOT use state (set!) or inheritance.

You must use #lang racket, rackunit, "extras.rkt", 2htdp/universe, and 2htdp/image. So your file should begin something like

#lang racket
(require rackunit)
(require "extras.rkt")
(require 2htdp/universe)   
(require 2htdp/image)      
You may require "sets.rkt" if you need it. You may not require any other libraries.

You have taken a job in a toy factory. You job is to simulate the following marvelous toy:

There are many unspecified parameters in the description above. Choose parameters (like speed, the exact way in which items grow and shrink, etc.) so that the result is visually satisfying.

I believe this problem is easier than the last one, so have some fun with it.

Your solution should be a file named toys.rkt and should provide the following interfaces and functions:

make-world : PosInt -> PlaygroundState<%>
RETURNS: a world with a target, but no toys, and in which any
square toys created in the future will travel at the given speed (in
pixels/tick). 

run : PosNum PosInt -> PlaygroundState<%> 
GIVEN: a frame rate (in seconds/tick) and a square-speed (in pixels/tick),
creates and runs a world in which square toys travel at the given
speed.  Returns the final state of the world.

make-square-toy : PosInt PosInt PosInt -> Toy<%>
GIVEN: an x and a y position, and a speed
RETURNS: an object representing a square toy at the given position,
travelling right at the given speed.

make-throbber: PosInt PosInt -> Toy<%>
GIVEN: an x and a y position
RETURNS: an object representing a throbber at the given position.

make-clock : PosInt PostInt -> Toy<%>
GIVEN: an x and a y position
RETURNS: an object representing a clock at the given position.

make-football : PosInt PostInt -> Toy<%>
GIVEN: an x and a y position
RETURNS: an object representing a football at the given position.

Interfaces:

(define PlaygroundState<%>
  (interface (WorldState<%>) ;; this means: include all the methods in
                             ;; WorldState<%>. 
    
    ;; -> Integer
    ;; RETURN: the x and y coordinates of the target
    target-x
    target-y

    ;; -> Boolean
    ;; Is the target selected?
    target-selected?

    ;; -> ListOfToy<%>
    get-toys

))

(define Toy<%> 
  (interface (Widget<%>)  ;; this means: include all the methods in
                          ;;  Widget<%>. 
 
    ;; -> Int
    ;; RETURNS: the x or y position of the center of the toy
    toy-x
    toy-y

    ;; -> Int
    ;; RETURNS: some data related to the toy.  The interpretation of
    ;; this data depends on the class of the toy.
    ;; for a square, it is the velocity of the square (rightward is
    ;; positive)
    ;; for a throbber, it is the current radius of the throbber
    ;; for the clock, it is the current value of the clock
    ;; for a football, it is the current size of the football (in
    ;; arbitrary units; bigger is more)
    toy-data


    ))

When you do this problem, remember the principle of Iterative Development: get something simple working, and then add features as necessary.

[*] This is a joke. But you still have to implement "f" as described.

Last modified: Wed Nov 11 09:05:37 Eastern Standard Time 2015